package com.tbit.uqbike.object.pojo.dto;

import com.tbit.uqbike.manager.exception.BaseException;
import com.tbit.uqbike.webmanager.util.csv.entity.DownloadDTO;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;
import org.springframework.util.StringUtils;

import javax.validation.constraints.NotNull;
import java.util.ArrayList;
import java.util.List;

/**
 * 财务总览查询参数
 *
 * @Author:yanlun
 * @DATE: 2022/11/18
 */
@Data
@NoArgsConstructor
@AllArgsConstructor
public class AccountDayStatFinancialDTO extends DownloadDTO {

    /**
     * 区域id 多个用,隔开
     */
    private String accountIds;
    /**
     * 品牌id
     */
    @NotNull(message = "品牌不能为空")
    private Integer brandId;

    /**
     * 分页参数，页码
     */
    private Integer pageIndex;
    /**
     * 分页参数，每页条数
     */
    private Integer pageSize;

    private String token;

    /**
     * 获取区域id List
     *
     * @return
     */
    public List<Integer> getAccountIdList() {
        List<Integer> accountIdList = new ArrayList<>();
        if (!StringUtils.hasText(accountIds)) {
            return accountIdList;
        }
        try {
            String[] accountIds = this.accountIds.split(",");
            for (String accountId : accountIds) {
                accountIdList.add(Integer.parseInt(accountId));
            }
        } catch (Exception e) {
            throw new BaseException("区域id有误");
        }

        return accountIdList;
    }
}
